package concurrent.c_006_Lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * https://www.cnblogs.com/jhxxb/p/11527735.html
 */
public class T13_LockSupport {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(i);
                if (i == 5) {
                    LockSupport.park();
                }
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t.start();
        LockSupport.unpark(t);

        // try {
        //     TimeUnit.SECONDS.sleep(8);
        // } catch (InterruptedException e) {
        //     e.printStackTrace();
        // }
        // System.out.println("after 8 senconds!");
        // LockSupport.unpark(t);
    }
}